export default {
  state: {
    isCollapse: false, // 控制菜单展开或者收起
    tabList: [
      {
        path: '/',
        name: 'home',
        label: '首页',
        icon: 's-home',
        url: 'Home/Home'
      }
    ]
  },
  mutations: {
    // 修改菜单展开收起
    collapseMenu (state) {
      state.isCollapse = !state.isCollapse
    },

    // 设置菜单为展开
    setMenuOpen (state) {
      state.isCollapse = false
    },

    // 更新面包屑数据
    selectMenu (state, val) {
      // console.log(val)
      // 判断添加的数据是否是首页
      if (val.name !== '首页') {
        const index = state.tabList.findIndex(item => item.name === val.name)
        // 没有这个路由数据，就添加进去
        if (index === -1) {
          state.tabList.push(val)
        }
      }
    },

    // 删除面包屑
    closeTag (state, item) {
      console.log(item)
      const index = state.tabList.findIndex(val => val.name === item.name)
      state.tabList.splice(index, 1)
    },

    // 清空tags
    clearTag (state) {
      state.tabList = [{
        path: '/',
        name: 'home',
        label: '首页',
        icon: 's-home',
        url: 'Home/Home'
      }]
    }
  }
}
